package com.ciis.base.param.service.impl;

import com.ciis.base.page.Page;
import com.ciis.base.param.mapper.ITbSysParamMapper;
import com.ciis.base.param.model.TbSysParam;
import com.ciis.base.param.service.ISysParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * Created with IntelliJ IDEA.
 * User: zhangdajun
 * Date: 14-4-12
 * Time: 下午10:11
 * To change this template use File | Settings | File Templates.
 */
@Service("sysParamService")
public class SysParamServiceImpl implements ISysParamService {

    @Autowired
    ITbSysParamMapper sysParamMapper;

    @Override
    public void saveSysParam(TbSysParam sysParam) throws Exception {
        sysParam.setId(UUID.randomUUID().toString());
        deleteSysParamByKey(sysParam.getParam_key());
        sysParamMapper.saveSysParam(sysParam);
    }

    @Override
    public List<TbSysParam> querySysParamById(String id) throws Exception {
        return sysParamMapper.querySysParamById(id);
    }

    @Override
    public List<TbSysParam> querySysParamByKey(String key) throws Exception {
        return sysParamMapper.querySysParamByKey(key);
    }

    @Override
    public void deleteSysParam(String id) throws Exception {
        sysParamMapper.deleteSysParam(id);
    }

    @Override
    public void deleteSysParamByKey(String key) throws Exception {
        sysParamMapper.deleteSysParamByKey(key);
    }

    @Override
    public void findPage(String key) throws Exception {
        TbSysParam sysParam = new TbSysParam();
        sysParam.setParam_key(key);
        Page<TbSysParam> paramPage = sysParamMapper.findPage(new Page(),sysParam);
        System.out.println("system out size : " + paramPage.getTotal());
        List<TbSysParam> result = paramPage.getRows();
        for(TbSysParam param : result){
            System.out.println(param.getParam_key()+","+param.getParam_value());
        }
    }
}
